<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@include file="/common/session.jsp" %>
<c:set var="shopId" value="${param.shopId}"/>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
    <LINK type="text/css" rel="stylesheet" href="${ctx}/css/default.css"/>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/MarketRpcService.js'></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/ShopRpcService.js'></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/UserRpcService.js'></script>
    <script type="text/javascript" src="${ctx}/js/loading.js"></script>
</head>
<body>
<br>
<form id="shopForm">
    <center>
        <input type="hidden" id="shopId" name="shopId" value="${shopId}">
        <input type="hidden" id="shopState" name="shopState" value="1">
        <input type="hidden" id="userId" name="userId">
        <input type="hidden" id="userType" name="userType" value="40">
        <input type="hidden" id="userRemark" name="userRemark" value="车商管理员">
        <input type="hidden" id="userState" name="userState" value="1">
        <input type="hidden" id="accountId" name="accountId">
        <table width="100%" cellpadding="5" cellspacing="5">
        	<tr>
                <td>
                    所属市场:
                </td>
                <td>
                    <select id="marketId" name="marketId">
                    </select>
                </td>
            </tr>
            <tr>
            	<td>
                    店铺名称:
                </td>
                <td>
                    <input type="text" placeholder="店铺名称(必填)" id="shopName" name="shopName" maxlength="20" required/>
                </td>
                <td>
                    店铺电话:
                </td>
                <td>
                    <input type="tel" placeholder="店铺电话(必填)" id="shopMobile" name="shopMobile" maxlength="11" required/>
                </td>
                <td>
                    店铺地址:
                </td>
                <td>
                    <input type="text" placeholder="店铺地址" id="shopAddress" name="shopAddress" maxlength="50" />
                </td>
            </tr>
            <tr>
                <td>
                    法人电话:
                </td>
                <td>
                    <input type="tel" placeholder="法人电话" id="shopLegalMobile" name="shopLegalMobile" maxlength="11" />
                </td>
                <td>
                    法人代表姓名:
                </td>
                <td>
                    <input type="text" placeholder="法人代表姓名" id="shopLegalName" name="shopLegalName" maxlength="10"/>
                </td>
                <td>
                    法人身份证:
                </td>
                <td>
                    <input type="text" placeholder="法人身份证" id="shopLegalNo" name="shopLegalNo" maxlength="18" />
                </td>
            </tr>
            <tr>
                <td>
                    负责人电话:
                </td>
                <td>
                    <input type="tel" placeholder="负责人电话(登录名,必填)" id="userMobile" name="userMobile" onchange="checkMobile()" maxlength="11" required/>
                </td>
            	<td>
                    负责人姓名:
                </td>
                <td>
                    <input type="text" placeholder="负责人姓名(必填)" id="userName" name="userName" maxlength="10" required/>
                </td>
                <td>
                    负责人身份证:
                </td>
                <td>
                    <input type="text" placeholder="负责人身份证" id="userNo" name="userNo" maxlength="18" />
                </td>
            </tr>
            <c:if test="${marketId == '1'}">
                <tr>
                    <td>
                        是否缴纳保证金：
                    </td>
                    <td>
                        <input type="radio" id="shopAuctionState1" name="shopAuctionState" value="1" required/>是&nbsp;&nbsp;&nbsp;
                        <input type="radio" id="shopAuctionState0" name="shopAuctionState" value="0" checked required/>否
                    </td>
                    <td colspan="4">
                    </td>
                </tr>
            </c:if>
            <c:if test="${marketId != '1'}">
                <tr>
                    <td>
                        是否缴纳保证金：
                    </td>
                    <td>
                        <input type="hidden" id="shopAuctionState" name="shopAuctionState" value="0" />
                    </td>
                    <td colspan="4">
                    </td>
                </tr>
            </c:if>
            <tr>
                <td style="border-top: 1px solid #e1ecf5" colspan="6" align="center">
                    <button type="button" onclick="insertOrUpdateShopUser()">保存</button>
                    <button type="button" onclick="callbackShopUser()">返回</button>
                </td>
            </tr>
    	</table>
    </center>
</form>
</body>
</html>

<script>
    //    显示市场列表
    var market = new Market();
    market.marketId = "${marketId}";
    MarketRpcService.selectMarketList(market, callbackSelectMarketList);

    function callbackSelectMarketList(list) {
        dwr.util.addOptions("marketId", list, "marketId", "marketName");
        dwr.util.setValue("marketId", "${marketId}");
        if ("${shopId}".length > 0) {
            selectUserShop();
        }
    }

    function selectUserShop() {
        var user = new User();
        user.shopId = "${shopId}";
        user.userType = dwr.util.getValue("userType");
        UserRpcService.selectUserList(user, callbackSelectUserList);
        var shop = new Shop();
        shop.shopId = "${shopId}";
        console.log(shop.shopId);
        ShopRpcService.selectShopList(shop, callbackSelectShopList);
    }

    function callbackSelectShopList(list) {
        dwr.util.setValues(list[0]);
        if(list[0].shopAuctionState == 1){
        	document.getElementById("shopAuctionState1").checked = true;
        }else{
	        document.getElementById("shopAuctionState0").checked = true;
        }
    }

    function callbackSelectUserList(list) {
        dwr.util.setValues(list[0]);
    }


    function checkMobile(){
        var user = new User();
        user.userState = 1;
        user.userMobile = dwr.util.getValue("userMobile");
        UserRpcService.selectUserList(user,callbackSelectMobileList);
        function callbackSelectMobileList(list){
            if (list.length > 0 ){
                dwr.util.setValue("userMobile",'');
                alert("手机号重复请重填");
            }
        }
    }

    function insertOrUpdateShopUser() {
        if (!validate($("shopForm"))) {
            return false
        }
        var shop = dwr.util.getValues("shopForm");
        var user = dwr.util.getValues("shopForm");
        user.shop = shop;
        if ("${shopId}".length > 0) {
            ShopRpcService.updateShopUser(user, callbackShopUser);
        } else {
            ShopRpcService.insertShopUser(user, callbackShopUser);
        }
    }

    function callbackShopUser(user) {
        location = "${ctx}/shop/shop_list.jsp";
    }

</script>
